using UnityEngine;

public class DeathMatchMod : MonoBehaviour
{
	public Texture2D TeamA;

	public Texture2D TeamB;

	public GUISkin skin;

	private PlayerConnector playerConnector;

	private void Awake()
	{
		if ((bool)UnitZ.playerManager)
		{
			UnitZ.playerManager.SavePlayer = false;
			UnitZ.playerManager.AskForRespawn = false;
			UnitZ.playerManager.AutoRespawn = false;
		}
	}

	private void Start()
	{
		StyleManager styleManager = (StyleManager)UnityEngine.Object.FindObjectOfType(typeof(StyleManager));
		if (!skin && (bool)styleManager)
		{
			skin = styleManager.GetSkin(0);
		}
	}

	private void Update()
	{
		if (!(UnitZ.playerManager == null))
		{
			if (UnitZ.playerManager.PlayingCharacter == null || ((bool)UnitZ.playerManager.PlayingCharacter && !UnitZ.playerManager.PlayingCharacter.IsAlive))
			{
				MouseLock.MouseLocked = false;
			}
			if (playerConnector == null)
			{
				playerConnector = (PlayerConnector)UnityEngine.Object.FindObjectOfType(typeof(PlayerConnector));
			}
			else
			{
				playerConnector.AutoSpawn = false;
			}
		}
	}

	private void OnGUI()
	{
		if (UnitZ.playerManager == null)
		{
			return;
		}
		if ((bool)skin)
		{
			GUI.skin = skin;
		}
		if ((bool)UnitZ.playerManager.PlayingCharacter && UnitZ.playerManager.PlayingCharacter.IsAlive)
		{
			return;
		}
		GUI.BeginGroup(new Rect(Screen.width / 2 - 400, Screen.height / 2 - 200, 800f, 400f));
		if (GUI.Button(new Rect(50f, 0f, 300f, 400f), TeamA))
		{
			if ((bool)playerConnector)
			{
				playerConnector.RequestSpawnWithTeam(1, 0);
			}
			else
			{
				UnitZ.playerManager.Respawn(1, 0);
			}
		}
		if (GUI.Button(new Rect(450f, 0f, 300f, 400f), TeamB))
		{
			if ((bool)playerConnector)
			{
				playerConnector.RequestSpawnWithTeam(2, 1);
			}
			else
			{
				UnitZ.playerManager.Respawn(2, 1);
			}
		}
		GUI.EndGroup();
	}
}
